<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/3/2
 * Time: 0:25
 */

namespace app\storage\service;


use think\Db;

class ReelsService
{
    static function getReelsInfo($reels,$storageUuid){
        if(is_array($reels)){
            $where['p.reel_id'] = ['in',$reels];
        }
        if(is_string($reels)){
            $where['p.reel_id'] = $reels;
        }
        $where['status'] = 1;
        $where['storage_uuid'] = $storageUuid;
        $reelsInfo = Db::table('iwh_purchase_detail')->alias('p')
            ->field("p.reel_id,ifnull(r.count,p.count) as count,p.sub_materiel_id")
            ->join(['iwh_reels'=>'r'],'p.reel_id = r.reel_id','left')
            ->where($where)
            ->select();
        if(count($reelsInfo) != count($reels)){
            $reels = is_string($reels)?[$reels]:$reels;
            $diff = array_diff($reels,array_column($reelsInfo->toArray(),'reel_id'));
            $diff = implode('、',$diff);
            return ret_template(false,$diff.'不存在库中');
        }else{
            return ret_template(true,'查询成功',$reelsInfo->toArray());
        }
    }
}